package com.mvc.app.implementations;

import com.container.app.annotations.Component;
import com.mvc.app.TemplateReader;
import org.antlr.stringtemplate.StringTemplate;

import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;

/**
 * Created with IntelliJ IDEA.
 * User: Georgiana.Scarlat
 * Date: 9/3/12
 * Time: 1:15 PM
 */
@Component
public class TemplateReaderFromFile implements TemplateReader {

    public StringTemplate readTemplate(String templateName) throws IOException {

        StringBuilder stringBuilder = new StringBuilder();
        String chunk;

        BufferedReader reader = new BufferedReader(new InputStreamReader(this.getClass().getClassLoader().getResourceAsStream(templateName)));

        while ((chunk = reader.readLine()) != null) {
            stringBuilder.append(chunk);
        }


        return new StringTemplate(stringBuilder.toString());
    }
}
